package com.jiang.utils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @author Jiang Junsheng
 * @create 2019/3/18
 * @since 1.0.0
 */
@Api("响应")
public class JsonResult<T> implements Serializable {
	private static final long serialVersionUID = -5127145149438726874L;
	public static final int SUCCESS = 200;
	public static final int FAILURE = 500;
	public static final String SUCCESS_CODE = "000000";
	public static final String SUCCESS_MESSAGE = "操作成功";
	public static final String FAILURE_CODE = "000000";
	public static final String FAILURE_MESSAGE = "操作失败";
	public static final String DATA_NOT_FOUND_CODE = "000000";
	public static final String DATA_NOT_FOUND_MESSAGE = "数据不存在";
	public static final String PARAMETERS_EMPTY_CODE = "000000";
	public static final String PARAMETERS_EMPTY_MESSAGE = "参数不能为空";
	public static final String PARAMETERS_ERROR_CODE = "000000";
	public static final String PARAMETERS_ERROR_MESSAGE = "传入参数错误";
	@ApiModelProperty(value = "请求状态")
	private String status;
	@ApiModelProperty(value = "请求结果")
	private String result;
	@ApiModelProperty(value = "返回具体内容")
	private T data;
	@ApiModelProperty(value = "请求结果码")
	private String code;
	@ApiModelProperty(value = "提示消息")
	private String message;

	public JsonResult() {
	}

	public JsonResult(boolean result) {
		this.status = "1";
		if (result) {
			this.result = "1";
			this.code = "000000";
			this.message = "操作成功";
		} else {
			this.result = "0";
			this.code = "000000";
			this.message = "操作失败";
		}

	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getResult() {
		return this.result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public T getData() {
		return this.data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return this.message;
	}

	public void setMessage(String message) {
		this.message = message;
	}


	public static JsonResult fail(String message) {
		JsonResult jsonResult = new JsonResult(false);
		jsonResult.setMessage(message);
		return jsonResult;
	}

	public static JsonResult fail(Object data) {
		JsonResult jsonResult = new JsonResult(false);
		jsonResult.setData(data);
		return jsonResult;
	}

	public static JsonResult success(String message) {
		JsonResult jsonResult = new JsonResult(true);
		jsonResult.setMessage(message);
		return jsonResult;
	}

	public static JsonResult success() {
		JsonResult jsonResult = new JsonResult(true);
		return jsonResult;
	}

	public static JsonResult success(Object data) {
		JsonResult jsonResult = new JsonResult(true);
		jsonResult.setData(data);
		return jsonResult;
	}

	public static JsonResult success(String message, Object data) {
		JsonResult jsonResult = new JsonResult(true);
		jsonResult.setMessage(message);
		jsonResult.setData(data);
		return jsonResult;
	}

	public static JsonResult successMap(String message, Object data) {
		JsonResult jsonResult = new JsonResult(true);
		jsonResult.setMessage(message);
		jsonResult.setData(data);
		return jsonResult;
	}
}
